<?xml version="1.0" encoding="UTF-8"?>
<!-- 
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:t="http://myfaces.apache.org/tomahawk" 
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:decorate template="/tema/padrao.xhtml">
        <ui:define name="centro">
                 <t:saveState value="#{osBean.os}" />
        <t:saveState value="#{osBean.servico}" />
        <t:saveState value="#{osBean.servicos}" />
        <t:saveState value="#{osBean.clientes}" />
        <t:saveState value="#{osBean.funcionarios}" />
            <h:form id="form">
                  <p:panel header="ORDEM DE SERVIÇO" >
                    <p:messages />
                    <h:panelGrid columns="3">
           
                   
                    <h:outputLabel value="FUNCIONÁRIO: *" />
                    <p:inputText id="func" value="#{osBean.os.funcionario.nome}" disabled="true"/>
                    <p:commandButton value="+," type="button" onclick="dlgFuncionario.show();"/>
                    
                    <h:outputLabel value="CLIENTE: *" />
                    <p:inputText id="cli" value="#{osBean.os.cliente.nome}" disabled="true"/>
                    <p:commandButton value="+." type="button" onclick="dlgCliente.show()"/>
                    
           
                    </h:panelGrid>
                    <br />
                    <p:commandButton value="SELECIONAR SERVIÇO" type="button" onclick="dlgServico.show()"/>
                    <br/>
                    <p:inputText id="servico" value="#{osBean.servico.nome}" />
                    <p:commandButton value="ADICIONAR SERVIÇO" actionListener="#{osBean.adicionarServico}" update="tabela"/>
                    <p:dataTable id="tabela" value="#{osBean.os.itensOrdemServico}" var="item" 
                                 paginator="true" emptyMessage="Nenhum registro adicionado.">
                        <f:facet name="header">
                            LISTA DE SERVIÇOS
                        </f:facet>
                        <p:column headerText="DESCRIÇÃO">
                            <h:outputText value="#{item.servico.nome}"/>
                        </p:column>
                        <p:column headerText="TIPO DE SERVIÇO">
                            <h:outputText />
                        </p:column>
                        <p:column headerText="VALOR">
                            <h:outputText />
                        </p:column>
                        <p:column headerText="EXCLUIR">
                            <p:commandButton value="X">
                                
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                    <p:commandButton id="btnSalvar" value="Salvar" actionListener="#{osBean.salvar}" update="form" process="@this" />
                <p:commandButton id="btnCancelar" value="Cancelar" action="/movimentos/osLista.jsf" immediate="true" ajax="false" />
                  </p:panel>
            </h:form>
            
            <p:dialog id="dlgCliente" header="SELEÇÃO DE CLIENTES" widgetVar="dlgCliente" 
                      appendToBody="true" >
                <h:form id="formCli" >
               <h:panelGrid columns="4"> 
                        <h:outputLabel value="CPF:" />

                        <p:inputText value="#{osBean.cpfConsultaCliente}"/>
                        <p:commandButton id="btnConsulta" value="CONSULTAR"                                      
                                         actionListener="#{osBean.consultarCliente}" 
                                         update="tabela"/>
                          </h:panelGrid>
                         <br />
                <p:dataTable id="tabela" value="#{osBean.clientes}" 
                             paginator="true" var="item"
                             emptyMessage="Nenhum registro encontrado.">
                    <f:facet name="header">
                        Clientes
                    </f:facet>
                    <p:column headerText="NOME">
                        <h:outputText value="#{item.nome}"/> 
                    </p:column>
                    <p:column headerText="CPF">
                        <h:outputText value="#{item.cpf}" converter="converterCnpjCpf"/>
                    </p:column>
                    <p:column headerText="SELECIONAR">
                      <p:commandButton id="btnSelecionar" value="X" oncomplete="dlgCliente.hide()" update=":form:cli" >
                            <f:setPropertyActionListener value="#{item}" target="#{osBean.os.cliente}" />
                        </p:commandButton>
                        
                    </p:column>

                </p:dataTable>
                  
                </h:form>
            </p:dialog>
            
            
             <p:dialog id="dlgFuncionario" header="SELEÇÃO DE FUNCINÁRIOS" 
                       widgetVar="dlgFuncionario" 
                      appendToBody="true" >
                <h:form id="formFunc">
               <h:panelGrid columns="4"> 
                        <h:outputLabel value="CPF:" />

                        <p:inputText value="#{osBean.cpfConsultaFuncionario}"/>
                        <p:commandButton id="btnConsulta" value="CONSULTAR"                                      
                                         actionListener="#{osBean.consultarFuncionario}" 
                                         update="tabela"/>
                        
                    </h:panelGrid>
                         <br />
                         <p:dataTable id="tabela" value="#{osBean.funcionarios}" paginator="true" var="item"
                             emptyMessage="Nenhum registro encontrado.">
                    <f:facet name="header">
                        Funcionários
                    </f:facet>
                    <p:column headerText="NOME">
                        <h:outputText value="#{item.nome}"/> 
                    </p:column>
                    <p:column headerText="CPF">
                        <h:outputText value="#{item.cpf}" converter="converterCnpjCpf"/>
                    </p:column>
                    <p:column headerText="SELECIONAR">
                     <p:commandButton id="btnSelecionar" value="X" oncomplete="dlgFuncionario.hide()" update=":form:func" >
                            <f:setPropertyActionListener value="#{item}" target="#{osBean.os.funcionario}" />
                        </p:commandButton>
                        
                    </p:column>

                </p:dataTable>
                </h:form>
            </p:dialog>
            
            
            <p:dialog id="dlgServico" header="SELEÇÃO DE SERVIÇOS" 
                       widgetVar="dlgServico" 
                      appendToBody="true" >
                <h:form id="formServ">
               <h:panelGrid columns="3"> 
                        <h:outputLabel value="Tipo Serviço:" />
                        <h:outputLabel value="Ativo:" />
                        <h:selectOneMenu id="serv" value="#{osBean.ativoInativoConsultaServico}" >  
                            <f:selectItem itemLabel="TODOS" />
                            <f:selectItem itemLabel="ATIVO" itemValue="#{true}" />
                            <f:selectItem itemLabel="INATIVO" itemValue="#{false}" />
                            
                        </h:selectOneMenu>            

                        <p:commandButton id="btnConsulta" value="CONSULTAR"                                      
                                         actionListener="#{osBean.consultarServico}"
                                         update="tabela"/>
                    </h:panelGrid>
                <br />
                <p:dataTable id="tabela" value="#{osBean.servicos}" paginator="true" var="item"
                             emptyMessage="Nenhum registro encontrado.">
                    <f:facet name="header">
                        Serviços

                    </f:facet>                    
                    <p:column headerText="DESCRIÇÃO">
                        <h:outputText value="#{item.nome}"/> 
                    </p:column>
                    <p:column headerText="TIPO SERVIÇO">
                    
                    </p:column>
                    <p:column headerText="VALOR">
                        <h:outputText value="#{item.valor}"/>
                    </p:column>
                    <p:column headerText="SELECIONAR">
                        <p:commandButton id="btnSelecionar" value="X" oncomplete="dlgServico.hide()" update=":form:servico" >
                            <f:setPropertyActionListener value="#{item}" target="#{osBean.servico}" />
                        </p:commandButton>
                    </p:column>

                </p:dataTable>

                </h:form>
            </p:dialog>
        </ui:define>
    </ui:decorate>
</html>